<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">


<!-- remove old header -->


<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>cogen API Reference Documentation
        - Class: Coroutine</title><meta name="MSSmartTagsPreventParsing" content="true" /><meta http-equiv="imagetoolbar" content="no" /><link href="css/default.css" rel="stylesheet" type="text/css" /><link href="css/pygments.css" rel="stylesheet" type="text/css" />
    <!-- <link rel="shortcut icon" href="/images/favicon.ico" type="image/vnd.microsoft.icon"/> -->
    <link rel="stylesheet" href="css/apydia.css" type="text/css" />
    <script src="js/jquery-1.2.1.pack.js" type="text/javascript"></script>
    <script src="js/apydia.js" type="text/javascript"></script>
	<link rel="icon" href="images/favicon.ico" type="image/x-icon" />
</head>
<body>
    <div id="page">
        <div id="browser">
            <div class="browser-section">
                <h2>Module Index</h2>
                <ul>
                    <li>
                        <a href="cogen.html">cogen</a>
                    </li><li>
                        <a href="cogen.common.html">cogen.common</a>
                    </li><li>
                        <a href="cogen.core.html">cogen.core</a>
                    </li><li class="active">
                        <a href="cogen.core.coroutines.html">cogen.core.coroutines</a>
                    </li><li>
                        <a href="cogen.core.events.html">cogen.core.events</a>
                    </li><li>
                        <a href="cogen.core.proactors.html">cogen.core.proactors</a>
                    </li><li>
                        <a href="cogen.core.proactors.base.html">cogen.core.proactors.base</a>
                    </li><li>
                        <a href="cogen.core.proactors.epoll_impl.html">cogen.core.proactors.epoll_impl</a>
                    </li><li>
                        <a href="cogen.core.proactors.poll_impl.html">cogen.core.proactors.poll_impl</a>
                    </li><li>
                        <a href="cogen.core.proactors.select_impl.html">cogen.core.proactors.select_impl</a>
                    </li><li>
                        <a href="cogen.core.pubsub.html">cogen.core.pubsub</a>
                    </li><li>
                        <a href="cogen.core.queue.html">cogen.core.queue</a>
                    </li><li>
                        <a href="cogen.core.schedulers.html">cogen.core.schedulers</a>
                    </li><li>
                        <a href="cogen.core.sockets.html">cogen.core.sockets</a>
                    </li><li>
                        <a href="cogen.core.util.html">cogen.core.util</a>
                    </li><li>
                        <a href="cogen.web.html">cogen.web</a>
                    </li><li>
                        <a href="cogen.web.async.html">cogen.web.async</a>
                    </li><li>
                        <a href="cogen.web.wsgi.html">cogen.web.wsgi</a>
                    </li>
                </ul>
            </div>
            <div class="browser-section">
                <h2>cogen.core.coroutines</h2>
                <ul>
                    <li class="active">
                        <a href="cogen.core.coroutines.Coroutine.html">Coroutine</a>
                    </li><li>
                        <a href="cogen.core.coroutines.local.html">local</a>
                    </li>
                </ul>
            </div>
            <div class="browser-section">
                <h2>Constructor</h2>
                <ul>
                    <li>
                        <a href="cogen.core.coroutines.Coroutine.html#constructor">__init__</a>
                    </li>
                </ul>
            </div>
            <div class="browser-section">
                <h2>Methods</h2>
                <ul>
                    <li>
                        <a href="cogen.core.coroutines.Coroutine.html#method-add_waiter">add_waiter</a>
                    </li><li>
                        <a href="cogen.core.coroutines.Coroutine.html#method-finalize">finalize</a>
                    </li><li>
                        <a href="cogen.core.coroutines.Coroutine.html#method-handle_error">handle_error</a>
                    </li><li>
                        <a href="cogen.core.coroutines.Coroutine.html#method-process">process</a>
                    </li><li>
                        <a href="cogen.core.coroutines.Coroutine.html#method-remove_waiter">remove_waiter</a>
                    </li><li>
                        <a href="cogen.core.coroutines.Coroutine.html#method-run_op">run_op</a>
                    </li>
                </ul>
            </div>
            <div class="browser-section">
                <h2>Attributes</h2>
                <ul>
                    <li>
                        <a href="cogen.core.coroutines.Coroutine.html#attribute-STATE_COMPLETED">STATE_COMPLETED</a>
                    </li><li>
                        <a href="cogen.core.coroutines.Coroutine.html#attribute-STATE_FAILED">STATE_FAILED</a>
                    </li><li>
                        <a href="cogen.core.coroutines.Coroutine.html#attribute-STATE_FINALIZED">STATE_FINALIZED</a>
                    </li><li>
                        <a href="cogen.web.wsgi.WSGIServer.html#attribute-STATE_NEED_INIT">STATE_NEED_INIT</a>
                    </li><li>
                        <a href="cogen.core.coroutines.Coroutine.html#attribute-STATE_RUNNING">STATE_RUNNING</a>
                    </li><li>
                        <a href="cogen.core.coroutines.Coroutine.html#attribute-caller">caller</a>
                    </li><li>
                        <a href="cogen.core.coroutines.Coroutine.html#attribute-coro">coro</a>
                    </li><li>
                        <a href="cogen.core.coroutines.Coroutine.html#attribute-debug">debug</a>
                    </li><li>
                        <a href="cogen.core.coroutines.Coroutine.html#attribute-exception">exception</a>
                    </li><li>
                        <a href="cogen.core.coroutines.Coroutine.html#attribute-f_args">f_args</a>
                    </li><li>
                        <a href="cogen.core.coroutines.Coroutine.html#attribute-f_kws">f_kws</a>
                    </li><li>
                        <a href="cogen.core.coroutines.Coroutine.html#attribute-lastop">lastop</a>
                    </li><li>
                        <a href="cogen.core.coroutines.Coroutine.html#attribute-name">name</a>
                    </li><li>
                        <a href="cogen.core.coroutines.Coroutine.html#attribute-prio">prio</a>
                    </li><li>
                        <a href="cogen.core.coroutines.Coroutine.html#attribute-result">result</a>
                    </li><li>
                        <a href="cogen.core.coroutines.Coroutine.html#attribute-running">running</a>
                    </li><li>
                        <a href="cogen.core.coroutines.Coroutine.html#attribute-state">state</a>
                    </li><li>
                        <a href="cogen.core.coroutines.Coroutine.html#attribute-waiters">waiters</a>
                    </li>
                </ul>
            </div>
        </div>
        <div id="content">
    <h1>Class: cogen.core.coroutines.Coroutine</h1>
    <div class="docstring rst"><p>We need a coroutine wrapper for generators and functions alike because
we want to run functions that don't return generators just like a
coroutine, also, we do some exception handling here.</p>
</div>
    <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/coroutines.py#84">View source</a>
    </li>
</ul>
    <div>
        <h2>Constructor</h2>
        <h3 id="constructor">
            __init__
            <span class="args">(self, coro, *args, **kws)</span>
        </h3>
        <div class="docstring rst"></div>
        <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
    </div>
    <div>
        <h2>Methods</h2>
            <h3 id="method-add_waiter">
                add_waiter
                <span class="args">(self, coro)</span>
            </h3>
            <div class="docstring rst"></div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="method-finalize">
                finalize
                <span class="args">(self)</span>
            </h3>
            <div class="docstring rst"></div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="method-handle_error">
                handle_error
                <span class="args">(self)</span>
            </h3>
            <div class="docstring rst"></div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="method-process">
                process
                <span class="args">(self, sched, coro)</span>
            </h3>
            <div class="docstring rst"></div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="method-remove_waiter">
                remove_waiter
                <span class="args">(self, coro)</span>
            </h3>
            <div class="docstring rst"></div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="method-run_op">
                run_op
                <span class="args">(self, op)</span>
            </h3>
            <div class="docstring rst"><p>Handle the operation:</p>
<ul class="simple">
<li>if coro is in STATE_RUNNING, send or throw the given op</li>
<li>if coro is in STATE_NEED_INIT, call the init function and if it
doesn't return a generator, set STATE_COMPLETED and set the result
to whatever the function returned.<ul>
<li>if StopIteration is raised, set STATE_COMPLETED and return self.</li>
<li>if any other exception is raised, set STATE_FAILED, handle error
or send it to the caller, return self</li>
</ul>
</li>
</ul>
<p>Return self is used as a optimization. Coroutine is also a Operation
which handles it's own completion (resuming the caller and the waiters).</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
    </div>
    <div>
        <h2>Attributes</h2>
            <h3 id="attribute-STATE_COMPLETED">STATE_COMPLETED</h3>
            <div class="docstring rst"></div>
            <h4>Value of STATE_COMPLETED</h4>
            <pre class="code"><code>2</code></pre>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="attribute-STATE_FAILED">STATE_FAILED</h3>
            <div class="docstring rst"></div>
            <h4>Value of STATE_FAILED</h4>
            <pre class="code"><code>3</code></pre>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="attribute-STATE_FINALIZED">STATE_FINALIZED</h3>
            <div class="docstring rst"></div>
            <h4>Value of STATE_FINALIZED</h4>
            <pre class="code"><code>4</code></pre>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="attribute-STATE_NEED_INIT">STATE_NEED_INIT</h3>
            <div class="docstring rst"></div>
            <h4>Value of STATE_NEED_INIT</h4>
            <pre class="code"><code>0</code></pre>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="attribute-STATE_RUNNING">STATE_RUNNING</h3>
            <div class="docstring rst"></div>
            <h4>Value of STATE_RUNNING</h4>
            <pre class="code"><code>1</code></pre>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="attribute-caller">caller</h3>
            <div class="docstring rst"></div>
            <h4>Value of caller</h4>
            <pre class="code"><code>&lt;member 'caller' of 'Coroutine' objects&gt;</code></pre>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="attribute-coro">coro</h3>
            <div class="docstring rst"></div>
            <h4>Value of coro</h4>
            <pre class="code"><code>&lt;member 'coro' of 'Coroutine' objects&gt;</code></pre>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="attribute-debug">debug</h3>
            <div class="docstring rst"></div>
            <h4>Value of debug</h4>
            <pre class="code"><code>&lt;member 'debug' of 'Coroutine' objects&gt;</code></pre>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="attribute-exception">exception</h3>
            <div class="docstring rst"></div>
            <h4>Value of exception</h4>
            <pre class="code"><code>&lt;member 'exception' of 'Coroutine' objects&gt;</code></pre>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="attribute-f_args">f_args</h3>
            <div class="docstring rst"></div>
            <h4>Value of f_args</h4>
            <pre class="code"><code>&lt;member 'f_args' of 'Coroutine' objects&gt;</code></pre>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="attribute-f_kws">f_kws</h3>
            <div class="docstring rst"></div>
            <h4>Value of f_kws</h4>
            <pre class="code"><code>&lt;member 'f_kws' of 'Coroutine' objects&gt;</code></pre>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="attribute-lastop">lastop</h3>
            <div class="docstring rst"></div>
            <h4>Value of lastop</h4>
            <pre class="code"><code>&lt;member 'lastop' of 'Coroutine' objects&gt;</code></pre>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="attribute-name">name</h3>
            <div class="docstring rst"></div>
            <h4>Value of name</h4>
            <pre class="code"><code>&lt;member 'name' of 'Coroutine' objects&gt;</code></pre>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="attribute-prio">prio</h3>
            <div class="docstring rst"></div>
            <h4>Value of prio</h4>
            <pre class="code"><code>&lt;member 'prio' of 'Coroutine' objects&gt;</code></pre>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="attribute-result">result</h3>
            <div class="docstring rst"></div>
            <h4>Value of result</h4>
            <pre class="code"><code>&lt;member 'result' of 'Coroutine' objects&gt;</code></pre>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="attribute-running">running</h3>
            <div class="docstring rst"></div>
            <h4>Value of running</h4>
            <pre class="code"><code>&lt;property object at 0xb7cfafa4&gt;</code></pre>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="attribute-state">state</h3>
            <div class="docstring rst"></div>
            <h4>Value of state</h4>
            <pre class="code"><code>&lt;member 'state' of 'Coroutine' objects&gt;</code></pre>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
            <h3 id="attribute-waiters">waiters</h3>
            <div class="docstring rst"></div>
            <h4>Value of waiters</h4>
            <pre class="code"><code>&lt;member 'waiters' of 'Coroutine' objects&gt;</code></pre>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk#0">View source</a>
    </li>
</ul>
    </div>
        </div>
        <div id="footer">
            Generated with <a href="http://apydia.ematia.de/" class="extern">
            Apydia 0.0.3</a>
        </div>
    </div>
</body>
</html>